import { followOrUnFollowAPI } from '@/apis/consult'
import type { DoctorItem, FollowType, Knowledge } from '@/types/consult'
import { ref } from 'vue'

// topic百科话题,knowledge百科文章,doc医生,disease疾病
export const useFollowOrUnFollow = (type: FollowType = 'doc') => {
  // 定义loading 响应式数据
  const loading = ref(false)
  const onFollowOrUnFollow = async (item: DoctorItem | Knowledge) => {
    loading.value = true
    // 发送请求
    try {
      await followOrUnFollowAPI(item.id, type)
      item.likeFlag = item.likeFlag === 1 ? 0 : 1
    } finally {
      loading.value = false
    }
  }
  return {
    loading,
    onFollowOrUnFollow
  }
}
